<template>
  <div class="sidebar">
    <div class="profile-card">
      <div class="profile-avatar">
        <img :src="userStore.userInfo?.avatar ? getStaticUrl(userStore.userInfo.avatar) : 'https://via.placeholder.com/100x100'" alt="个人头像" />
      </div>
      <h2 class="profile-name">{{ userStore.userInfo?.nickname || '博客作者' }}</h2>
      <p class="profile-bio">{{ userStore.userInfo?.bio || '热爱技术与分享的程序员，致力于Web开发和全栈技术' }}</p>
      <div class="profile-social">
        <a href="#" class="social-icon"><i class="github-icon"></i></a>
        <a href="#" class="social-icon"><i class="twitter-icon"></i></a>
        <a href="#" class="social-icon"><i class="linkedin-icon"></i></a>
      </div>
    </div>
    
    <div class="site-stats">
      <h3 class="widget-title">站点统计</h3>
      <ul class="stats-list">
        <li><FileTextOutlined /> 文章总数: <span>{{ stats.articleCount || 0 }}</span></li>
        <li><EyeOutlined /> 访问总数: <span>{{ stats.viewCount || 0 }}</span></li>
        <li><CommentOutlined /> 评论总数: <span>{{ stats.commentCount || 0 }}</span></li>
        <li><TeamOutlined /> 用户总数: <span>{{ stats.userCount || 0 }}</span></li>
        <li><CalendarOutlined /> 运行天数: <span>{{ stats.dayCount || 0 }}</span></li>
      </ul>
    </div>
    
    <div class="contact-info">
      <h3 class="widget-title">联系方式</h3>
      <ul class="contact-list">
        <li><MailOutlined /> 邮箱: <a href="mailto:contact@example.com">contact@example.com</a></li>
        <li><PhoneOutlined /> 电话: <a href="tel:+1234567890">123-456-7890</a></li>
        <li><EnvironmentOutlined /> 地址: 北京市海淀区中关村</li>
      </ul>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { useUserStore } from '@/stores/user';
import { getSiteStats } from '@/api/stats'; // 假设有一个获取站点统计数据的API
import { getStaticUrl } from '@/utils/url';
import { 
  FileTextOutlined, 
  EyeOutlined, 
  CommentOutlined,
  TeamOutlined,
  CalendarOutlined,
  MailOutlined,
  PhoneOutlined,
  EnvironmentOutlined
} from '@ant-design/icons-vue';

const userStore = useUserStore();
const stats = ref({
  articleCount: 0,
  viewCount: 0,
  commentCount: 0,
  userCount: 0,
  dayCount: 0
});

onMounted(async () => {
  try {
    // 加载站点统计数据
    const data = await getSiteStats();
    stats.value = data;
  } catch (error) {
    console.error('获取站点统计失败:', error);
  }
});
</script>

<style scoped>
.sidebar {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.profile-card, .site-stats, .contact-info {
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.profile-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 15px;
  border: 3px solid #42b983;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-name {
  text-align: center;
  margin: 0 0 10px;
  color: #333;
}

.profile-bio {
  text-align: center;
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 15px;
}

.profile-social {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.social-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #42b983;
  transition: all 0.3s;
}

.social-icon:hover {
  background-color: #42b983;
  color: white;
}

.site-stats h3, .contact-info h3 {
  margin-top: 0;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
  color: #42b983;
}

.stats-list, .contact-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.stats-list li, .contact-list li {
  display: flex;
  align-items: center;
  padding: 8px 0;
  color: #666;
  border-bottom: 1px dashed #eaeaea;
}

.stats-list li:last-child, .contact-list li:last-child {
  border-bottom: none;
}

.stats-list i, .contact-list i {
  margin-right: 10px;
  width: 20px;
  text-align: center;
  color: #42b983;
}

.contact-list a {
  color: #666;
  text-decoration: none;
  transition: color 0.3s;
}

.contact-list a:hover {
  color: #42b983;
}

/* 移除旧的图标样式 */
.icon-article::before,
.icon-view::before,
.icon-comment::before,
.icon-user::before,
.icon-calendar::before,
.icon-email::before,
.icon-phone::before,
.icon-location::before {
  content: none;
}

/* 调整图标样式 */
.anticon {
  margin-right: 10px;
  color: #42b983;
}
</style> 